/*
 * @Author: minglic minglic@foxmail.com
 * @Date: 2023-10-21 09:08:27
 * @LastEditors: minglic minglic@foxmail.com
 * @LastEditTime: 2023-10-21 09:09:57
 * @FilePath: \go2023\core\utils\data\sqlite.go
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package data

import (
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
)

var db *gorm.DB

//打开数据库连接
func OpenSqlite(file string) {
	var err error

	db, err = gorm.Open(
		sqlite.Open(file),
		&gorm.Config{
			Logger: logger.Default.LogMode(logger.Info),
		},
	)

	if err != nil {
		panic(err)
	}
}

func GetDb() *gorm.DB {
	return db
}
